package com.macro.mall.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.CiCollegeInfo;
import com.macro.mall.service.CiCollegeInfoService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * CiCollegeInfo的路由接口服务
 * 
 * @author 
 *
 */
@Slf4j
@RestController
@RequestMapping("college")
@Api(tags = "学院管理", description = "学院管理")
public class CiCollegeInfoController {

	/** CiCollegeInfoService服务 */
	@Autowired
	private CiCollegeInfoService ciCollegeInfoService;
	
	/**
	 * 查询所有CiCollegeInfo数据的方法
	 * @param
	 * @return
	 */
	@GetMapping(value = "/list", produces = {"application/json;charset=UTF-8"})
	public CommonResult find(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                             @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
		return CommonResult.success(CommonPage.restPage(ciCollegeInfoService.find(pageNum,pageSize)));
	}
	
	/**
	 * 通过id查询CiCollegeInfo数据的方法
	 * @param id
	 * @return
	 */
	@GetMapping(value = "/getById", produces = {"application/json;charset=UTF-8"})
	public CommonResult findOne(@RequestParam(name="id") Integer id) {
		return CommonResult.success(ciCollegeInfoService.findOne(id));
	}
	
	/**
	 * 插入CiCollegeInfo属性不为空的数据方法
	 * @param
	 * @return
	 */
	@PostMapping(value = "/save", produces = {"application/json;charset=UTF-8"})
	public CommonResult save(@Valid @RequestBody CiCollegeInfo value) {
        CommonResult data = ciCollegeInfoService.saveNotNull(value);
        return CommonResult.success(null);
	}
	
	/**
	 * 更新CiCollegeInfo属性不为空的数据方法
	 * @param
	 * @return
	 */
	@PostMapping(value = "/update", produces = {"application/json;charset=UTF-8"})
	public CommonResult update(@Valid @RequestBody CiCollegeInfo value) {
        CommonResult data = ciCollegeInfoService.updateNotNullById(value);
        return CommonResult.success(null);
	}

	/**
	 * 通过id删除CiCollegeInfo数据方法
	 * @param id
	 * @return
	 */
	@GetMapping(value = "/deleteId", produces = {"application/json;charset=UTF-8"})
	public CommonResult delete(@RequestParam(name="id") Integer id) {
        CommonResult data = ciCollegeInfoService.deleteById(id);
        return CommonResult.success(null);
	}
}
